//
//  ViewController.m
//  20-JSONHomework
//
//  Created by Snow on 16/8/10.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "FindCar.h"
#import "Brand.h"
#import "Brandlist.h"
#import "MyTableViewCell.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (nonatomic, strong) FindCar *findcar;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
        return _findcar.result.brandlist.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    return cell;
}
- (void)handleData
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"AllCar" ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSError *error = nil;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    _findcar = [FindCar findCarWithDic:dic];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return self.findcar.result.brandlist[section].letter;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
